/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import model.Agenda;
import model.AgendaDAO;
import model.Compromisso;
import model.CompromissoDAO;
import model.Paciente;
import model.Profissional;
import model.ProfissionalDAO;

import model.Usuario;
import model.UsuarioDAO;

/**
 *
 * @author 0731110
 */
 public class TrataCadastroAgenda extends Comando {

    @Override
    public void executar(HttpServletRequest request, HttpServletResponse response) throws ClassNotFoundException, SQLException, IOException, ServletException {
        
        response.setContentType("text/html;charset=UTF-8");

        String profissionalId= request.getParameter("profissional");
        String nome= request.getParameter("nome");
        String cpf= request.getParameter("cpf");
        String rg= request.getParameter("rg");
        String datanasc= request.getParameter("datanasc");
        String endereco= request.getParameter("endereco");
        String telefone= request.getParameter("telefone");
        String celular= request.getParameter("celular");
        String email= request.getParameter("email");
        
       
        
        PrintWriter out = response.getWriter();
        try {
            
            Profissional pro = new Profissional(nome, cpf, rg, datanasc, endereco, telefone, celular, email);
            pro.setIdPessoa(Integer.parseInt(profissionalId));
            
            Agenda agenda = new Agenda(pro, nome, cpf, rg, datanasc, endereco, telefone, celular, email);
                        
            AgendaDAO ddao = new AgendaDAO();
            ddao.inserir(agenda);
            
            response.sendRedirect("agendaCadastrada.jsp");
       } catch(SQLException ex){
            throw new ServletException(ex);
        }catch (ClassNotFoundException cnfe) {
            throw new ServletException(cnfe);
        }
            out.close();
    }
}
